package com.example.easybuy.service.impl;

import com.example.easybuy.mapper.EasybuyUserMapper;
import com.example.easybuy.pojo.EasybuyNews;
import com.example.easybuy.pojo.EasybuyUser;
import com.example.easybuy.service.EasybuyUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 张子晨
 * @since 2021-03-12
 */
@Service
public class EasybuyUserServiceImpl implements EasybuyUserService {

    @Autowired
    EasybuyUserMapper easybuyUserMapper;

    //用户登录
    public EasybuyUser login(String loginName, String password) {
        return easybuyUserMapper.login(loginName, password);
    }

    //查询用户是否存在
    @Override
    public String searchUser(String loginName, String password) {
        return easybuyUserMapper.searchUser(loginName, password);
    }

    //注册用户
    @Override
    public int registerUser(String loginName, String password, String email, String mobile) {
        return easybuyUserMapper.registerUser(loginName, password, email, mobile);
    }

    //判断登录名是否重名
    @Override
    public int loginNameCount(String loginName) {
        int i = easybuyUserMapper.loginNameCount(loginName);
        return i;
    }

    @Override
    public EasybuyUser selectUserById(Integer id) {
        return easybuyUserMapper.selectUserById(id);
    }

    @Override
    public PageInfo<EasybuyUser> userAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<EasybuyUser> list = easybuyUserMapper.getUserList();
        PageInfo<EasybuyUser> pageInfo = new PageInfo<EasybuyUser>(list);
        return pageInfo;
    }

    @Override
    public int delUser(Integer id) {
        return easybuyUserMapper.delUser(id);
    }

}
